﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ReBasic.Helper
{
    public class ViewHelper
    {
        public static string ViewFile(string FilePath, bool isRandom)
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                Random rdm = new Random();
                FileStream fsr = new FileStream(FilePath, FileMode.Open);
                StreamReader sr = new StreamReader(fsr, Encoding.UTF8);
                for (int i = 0; i < 50; i++)
                {
                    int k = 0;
                    if (isRandom)
                        k = rdm.Next(10000);
                    while (!sr.EndOfStream)
                    {
                        string s = sr.ReadLine();
                        if (k-- > 0) continue;
                        sb.Append(">>>> ").Append(s).Append("\r\n");
                        break;
                    }
                }
                sr.Close();
                fsr.Close();
            }
            catch
            {
                sb.Append("Unable to open file.\r\n");
            }
            finally
            {
                ;
            }
            return sb.ToString();
        }
    }
}
